#============================================================
#    Plugin
#============================================================
# - datetime: 2022-10-01 07:51:21
#============================================================

##  底部收藏栏

@tool
extends EditorPlugin


const META_KEY_VISIBLE = &"collection_panel_visible"
const PANEL_SCENE = preload("src/panel/bottom_panel.tscn")
const PANEL_NAME = "Collection"


var bottom_panel = PANEL_SCENE.instantiate() as Control
var can_set_visible_enabled = true


#============================================================
#  内置
#============================================================
func _ready():
	bottom_panel.custom_minimum_size.y = 200
	add_control_to_bottom_panel(bottom_panel, PANEL_NAME)
	bottom_panel.reloaded.connect(_reload)
	
	make_bottom_panel_item_visible(bottom_panel)


func _exit_tree():
	if is_instance_valid(bottom_panel):
		remove_control_from_bottom_panel(bottom_panel)


func _reload():
	can_set_visible_enabled = false
	var tree = get_tree()
	if is_instance_valid(bottom_panel):
		remove_control_from_bottom_panel(bottom_panel)
	var plugin_name = self.get_script().resource_path.get_base_dir().get_file()
	var editor_interface = self.get_editor_interface()
	editor_interface.set_plugin_enabled(plugin_name, false)
	await tree.create_timer(0.1).timeout
	editor_interface.set_plugin_enabled(plugin_name, true)
	print("已重新加载 ", plugin_name, " 插件")

